package MyLog;

import java.util.Calendar;

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;

public class MyLog
{
  private static Logger logger = Logger.getRootLogger();

  public MyLog()
  {
    try {
      SimpleLayout layout = new SimpleLayout();
      ConsoleAppender consoleAppender = new ConsoleAppender( layout );
      logger.addAppender( consoleAppender );
      FileAppender fileAppender = new FileAppender( layout, "logs/FeuerwehrDB.log", false );
      logger.addAppender( fileAppender );
      // ALL | DEBUG | INFO | WARN | ERROR | FATAL | OFF:
      logger.setLevel( Level.INFO );
    } catch( Exception ex ) {
      System.out.println( ex );
    }
    /*logger.debug( "Meine Debug-Meldung" );
    logger.info(  "Meine Info-Meldung"  );
    logger.warn(  "Meine Warn-Meldung"  );
    logger.error( "Meine Error-Meldung" );
    logger.fatal( "Meine Fatal-Meldung" );*/
    logger.info(MyLog.getLogTime() + "Logger started");
  }
  
  public static Logger getLogger(){
	  return logger;
  }
  
public static String getLogTime(){
		StringBuffer sb = new StringBuffer("");
		Calendar c = Calendar.getInstance();
		sb.append(c.get(Calendar.YEAR));
		sb.append("/");
		sb.append(c.get(Calendar.MONTH));
		sb.append("/");
		sb.append(c.get(Calendar.DAY_OF_MONTH));
		sb.append(" ");
		sb.append(c.get(Calendar.HOUR_OF_DAY));
		sb.append(":");
		sb.append(c.get(Calendar.MINUTE));
		sb.append(":");
		sb.append(c.get(Calendar.SECOND));
		sb.append(" - ");
	  return sb.toString();
  }
}
